package com.model.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import com.mysql.jdbc.Connection;

public class DBUtil {
 	 private Connection conn=null;
	 private String user;
	 private String password;
	 private String url;
	 private String  classname;
	 private  Properties proper=new Properties(); 
	 private static DBUtil db; 
      private DBUtil(){}   
       public static DBUtil getInstance(){
    	   if(db==null){
    		   db=new DBUtil();
    	   }
    	   return db;
       }
     
    public Connection getConnection(){
   	      try {
   	    	 InputStream inStream=DBUtil.class.getResourceAsStream("db.properties");
   	    	 proper.load(inStream);
			 user=proper.getProperty("user");
	   	     password=proper.getProperty("password");
	   	     url=proper.getProperty("url");
	   	     classname=proper.getProperty("classname");
	    	 Class.forName(classname);
	    	 conn=(Connection) DriverManager.getConnection(url, user, password);		
   	      } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    	  return  conn;
    	 
    	 
     }  


          

}
